source 'https://cdn.cocoapods.org/'

deployment_target = '12.4'
# Uncomment the next line to define a global platform for your project
platform :ios, deployment_target
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative './mendix_utils'
generate_mendix_delegate

def common_pods
  # Comment the next line if you don't want to use dynamic frameworks
  # use_frameworks!

  # RN development pods
  config = use_native_modules!
  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is disabled by default to avoid incompatibilities and slowness with Mendix Runtime.
    :hermes_enabled => false,
    :fabric_enabled => false,
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => FlipperConfiguration.enabled(["Debug"], {'Flipper' => '0.189.0' , 'Flipper-DoubleConversion' => '1.1.7'}),
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )
  # RN pods end

  # Manually linked dependencies
  pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'

  # Third party dependencies of dependencies
  pod 'IQKeyboardManager'

  # At least one permission must be added when `react-native-permissions` used
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary"

  # Required MendixNative dependency
  pod 'SSZipArchive'

  # Required for Push notifications
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCore', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
end

target 'nativeTemplate' do
  generate_pod_dependencies
  use_native_modules!
  common_pods
  # Intentionally left empty
end

target 'dev' do
  generate_pod_dependencies
  use_native_modules!
  common_pods
  # Intentionally left empty
end

post_install do |installer|
  react_native_post_install(
    installer,
    # Set `mac_catalyst_enabled` to `true` in order to apply patches
    # necessary for Mac Catalyst builds
    :mac_catalyst_enabled => false
  )

  __apply_Xcode_12_5_M1_post_install_workaround(installer)

  installer.pods_project.build_configurations.each do |config|
    config.build_settings['ENABLE_BITCODE'] = 'YES'
    config.build_settings['OTHER_LDFLAGS'] ||= ['$(inherited)']
    if config.name == "Debug"
      config.build_settings['DEAD_CODE_STRIPPING'] = 'YES'
      config.build_settings['OTHER_LDFLAGS'] << "-fembed-bitcode-marker"
      config.build_settings['BITCODE_GENERATION_MODE'] = "marker"
    else
      config.build_settings['OTHER_LDFLAGS'] << "-fembed-bitcode"
      config.build_settings['BITCODE_GENERATION_MODE'] = "bitcode"
    end
  end

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if target.name == "React"
        if config.name == "ReleaseDevApp"
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << "DEBUG=1"
        end
      end
    end
  end
  # Ensure deployment_target is set correctly for all projects
  installer.generated_projects.each do |project|
      project.targets.each do |target|
          target.build_configurations.each do |config|
              config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
          end
      end
      project.build_configurations.each do |bc|
          bc.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
      end
  end
end
